package com.example.ui.controller;

import com.example.ui.pojo.Person;
import com.example.ui.service.feign.ProducerService;
import com.example.ui.service.ribbon.ConsumerHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 测试
 *
 * @author 86188
 */
@RestController
public class TestController {
    @Autowired
    private ProducerService producerService;

    @Autowired
    private ConsumerHystrixService consumerHystrixService;

    @RequestMapping("/getMessage")
    public String getMessage() {

        return consumerHystrixService.getMessage();
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    List<Person> save(@RequestBody String name) {
        return producerService.save(name);
    }

    @RequestMapping("/list")
    public List<Person> list() {
        return producerService.list();
    }

    @RequestMapping("/hello/{name}")
    public String hello(@PathVariable("name") String name) {
        return producerService.hello(name);
    }

    @RequestMapping("/ping")
    public String ping() {
        return "pang";
    }
}
